//
// Created by Administrator on 2021/11/22.
//

/*
 * 给定一个字符串s，通过字符串s中的每个字母转变为大小写，我们可以获得一个新的字符串，返回所有可能得到的字符串集合
 * */
# include<iostream>
# include<string>
# include<vector>
# include"permute.cpp"
using namespace std;

void letterCasePermutationHelper(string s,string &storeString, vector<string> &result){
    //base case
    if(s.length()==0){
        //put storeString in result
        result.push_back(storeString);
        return;
    }else{
        //recursion case
        //如果s[0]是letter的话才进行操作，数字的话不进行操作
        char cur = s[0];
        if(!isdigit(cur)){
            //choose-explore : 决定s[0]变大写还是不变
            //不变
            storeString = storeString+cur;
            char cur_change;
            if(isupper(cur)){
                cur_change = tolower(cur);
            }else{
                cur_change = toupper(cur);
            }
            s = s.substr(1,s.length()-1);
            cout<<"choose "<<cur<<" storeString="<<storeString<<" s= "<<s<<endl;
            letterCasePermutationHelper(s,storeString,result);
            //变大写
            storeString = storeString.substr(0,storeString.length()-1);
            storeString = storeString+cur_change;
            cout<<"choose "<<cur_change<<" storeString="<<storeString<<" s= "<<s<<endl;
            letterCasePermutationHelper(s,storeString,result);
            //un-choose
            s = cur+s;
            storeString = storeString.substr(0,storeString.length()-1);
            cout<<"un-choose "<<cur<<" storeString="<<storeString<<" s= "<<s<<endl;
        }else{
            //数字
            storeString = storeString+cur;
            s = s.substr(1,s.length()-1);
            cout<<"choose "<<cur<<" storeString="<<storeString<<" s= "<<s<<endl;
            letterCasePermutationHelper(s,storeString,result);
            //un-choose
            s = cur+s;
            storeString = storeString.substr(0,storeString.length()-1);
            cout<<"un-choose "<<cur<<" storeString="<<storeString<<" s= "<<s<<endl;
        }
        return;
    }
}

vector<string> letterCasePermutation(string s){
    vector<string> resultString;
    string storeString;
    letterCasePermutationHelper(s,storeString,resultString);
    return resultString;
}

void printStringVector(vector<string> vec){
    for (string i : vec){
        cout<<i<<" ";
    }
    cout<<endl;
}

int main(){
    string s = "C";
    vector<string> result = letterCasePermutation(s);
    printStringVector(result);
    return 0;
}

